package com.bjsxt.service.impl;

import com.bjsxt.mapper.HostMapper;
import com.bjsxt.mapper.HostPowerMapper;
import com.bjsxt.pojo.Host;
import com.bjsxt.pojo.PageA;
import com.bjsxt.service.HostService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class HostServiceImpl implements HostService {
    @Autowired
    private HostMapper hostMapper;

    @Autowired
    private HostPowerMapper hostPowerMapper;

    @Override
    public PageA<Host> selectHostSice(Integer page, Integer rows,Host host) {
        Page pg = PageHelper.startPage(page, rows);

        List<Host> hosts = hostMapper.selectHost(host);

        PageA<Host> pgg=new PageA<>(hosts,pg.getTotal());

        return pgg;
    }

    @Override
    public Integer updateHostSice(Integer strong, Integer hid) {

        return hostMapper.updateHost(strong, hid);
    }

    @Override
    public Integer insetHostSice(Host host) {
        Integer integer1 = hostMapper.insetHost(host);
        Integer integer = hostPowerMapper.insertHostPower(host.getHid());


        if (integer>0&&integer1>0){
            return 1;
        }
        return 0;
    }

    @Override
    public Integer updateHostStatusSice(Integer hid, String status) {

        return hostMapper.updateHostStatus(hid, status);
    }
}
